//package com.ibeetl.bbs.util;
//
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
//import org.beetl.core.GroupTemplate;
//import org.beetl.core.resource.ClasspathResourceLoader;
//import org.beetl.core.resource.WebAppResourceLoader;
//import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
//import org.beetl.ext.spring.BeetlSpringViewResolver;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.DefaultResourceLoader;
//import org.springframework.core.io.support.ResourcePatternResolver;
//import org.springframework.core.io.support.ResourcePatternUtils;
//import org.springframework.web.servlet.ViewResolver;
//
//import com.ibeetl.bbs.common.Const;
//import com.kfit.ibeetl.bbs.common.Functions;
//
///**
// * beetl 配置
// * @author 草原狼
// * @date 2017-6-23
// */
//@Configuration
//public class BeetlConfiguration {
//	private Logger logger =  LoggerFactory.getLogger(this.getClass());
//	
//	/*
//	@Bean(initMethod = "init", name = "beetlConfig")
//    public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration(@Qualifier("functions") Functions fn) {
//
//        BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();
//        ResourcePatternResolver patternResolver = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader());
//
//        try {
//            ClasspathResourceLoader cploder = new ClasspathResourceLoader(BeetlConfiguration.class.getClassLoader(),"templates/");
//            beetlGroupUtilConfiguration.setResourceLoader(cploder);
//
//            beetlGroupUtilConfiguration.setConfigFileResource(patternResolver.getResource("classpath:beetl.properties"));
//            Map<String, Object> functionPackages = new HashMap<String, Object>();
//            functionPackages.put("c", fn);
//            beetlGroupUtilConfiguration.setFunctionPackages(functionPackages);
//            beetlGroupUtilConfiguration.setSharedVars(new HashMap<String, Object>() {            	
//				private static final long serialVersionUID = 7167033020193046364L;
//
//			{
//                put("v", Const.TIMESTAMP);
//                //put("moduleList", moduleDao.all());
//            }});
//            logger.info("beetlGroupUtilConfiguration "+beetlGroupUtilConfiguration);
//            return beetlGroupUtilConfiguration;
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//
//    }
//    */
//	@Bean(initMethod = "init", name = "beetlConfig")
//	public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration(){
//		BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();
//		ResourcePatternResolver patternResolver = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader());
//		try{
//			
//			 logger.info("path "+patternResolver.getResource("classpath:/templates").getFile().getAbsolutePath());
//			WebAppResourceLoader webAppResourceLoader = new WebAppResourceLoader(patternResolver.getResource("classpath:/templates").getFile().getAbsolutePath());
//			GroupTemplate gt = new GroupTemplate();
//			//gt.registerFunctionPackage("so", new ShiroExt());
//			beetlGroupUtilConfiguration.setResourceLoader(webAppResourceLoader);
//			
//		}catch(IOException e){
//			e.printStackTrace();
//		}
//		 
//		//读取配置文件
//		beetlGroupUtilConfiguration.setConfigFileResource(patternResolver.getResource("classpath:beetl.properties"));
//		 logger.info("beetlGroupUtilConfiguration "+beetlGroupUtilConfiguration);
//		return beetlGroupUtilConfiguration;
//	} 
//	
//	
//	
//    @Bean(name = "beetlViewResolver")
//    public ViewResolver getBeetlSpringViewResolver(@Qualifier("beetlConfig") BeetlGroupUtilConfiguration beetlGroupUtilConfiguration) {
//        BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
//        beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
//        beetlSpringViewResolver.setOrder(0);
//        beetlSpringViewResolver.setConfig(beetlGroupUtilConfiguration);
//        
//       // InternalResourceViewResolver resolver = new InternalResourceViewResolver();
//        //beetlSpringViewResolver.setPrefix("templates/");
//        //beetlSpringViewResolver.setSuffix(".html");
//        //beetlSpringViewResolver.setExposeContextBeansAsAttributes(true);
//        logger.info("beetlSpringViewResolver "+beetlSpringViewResolver);
//        return beetlSpringViewResolver;
//    }
//    
//   
//}
